import { useState, useEffect } from 'react';

export function useTheme() {
  const [theme, setTheme] = useState<'light' | 'dark'>(() => {
    const hour = new Date().getHours();

    return hour >= 6 && hour < 18 ? 'light' : 'dark';
  });

  const toggleTheme = () => {
    setTheme((prev) => (prev === 'light' ? 'dark' : 'light'));
  }

  useEffect(() => {
    document.body.removeAttribute('theme-mode');
    switch (theme) {
      case 'light':
        break;
      case 'dark':
        document.body.setAttribute('theme-mode', 'dark');
        break;
      default:
        break;
    }
  }, [theme]);

  return {
    theme,
    toggleTheme
  };
}
